//
//  OrderDetailViewController.m
//  CommunityApp
//
//  Created by 秦乾龙 on 16/12/23.
//  Copyright © 2016年 秦乾龙. All rights reserved.
//

#import "OrderDetailViewController.h"
#import "AFNetworking.h"//主要用于网络请求方法
#import "UIKit+AFNetworking.h"//里面有异步加载图片的方法
#import "AFHTTPSessionManager.h"
#import "UIButton+WebCache.h"
#import "UIImageView+WebCache.h"
#import "NavView.h"
#import "ZYButton.h"
#define kScreenW [UIScreen mainScreen].bounds.size.width
#define kScreenH [UIScreen mainScreen].bounds.size.height
#define kScale   ([UIScreen mainScreen].bounds.size.width)/750
@interface OrderDetailViewController ()<UIScrollViewDelegate,UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,retain)UITableView *mainTableView;
@property (nonatomic,retain)UIButton *selectClassBtn;
@property (nonatomic,retain)UIView *lineView;

@end

@implementation OrderDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    NavView *nav = [[NavView alloc]initWithTitle:@"订单详情" LeftImage:[ UIImage imageNamed:@"返回"]];
    nav.frame = CGRectMake(0, 20, kScreenW, 44);
    nav.backgroundColor = [UIColor colorWithRed:32/255.0 green:32/255.0 blue:32/255.0 alpha:1.0f];
    nav.titleLable.textColor = [UIColor whiteColor];
    self.view.backgroundColor = [UIColor colorWithRed:32/255.0 green:32/255.0 blue:32/255.0 alpha:1.0f];
    [nav.leftBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:nav];
    UIView *backgroundView = [[UIView alloc]initWithFrame:CGRectMake(0, 64, kScreenW, kScreenH-64)];
    backgroundView.backgroundColor = [UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1.0f];
    [self.view addSubview:backgroundView];
    
    UILabel *countdownLable = [[UILabel alloc]init];
    countdownLable.frame = CGRectMake(0, 64, kScreenW, 100*kScale);
    countdownLable.font = [UIFont systemFontOfSize:15];
    countdownLable.text = @"24小时23分钟15秒以后自动取消订单";
    countdownLable.textAlignment = NSTextAlignmentCenter;
    countdownLable.backgroundColor = [UIColor whiteColor];
    countdownLable.textColor = [UIColor colorWithRed:14/255.0 green:161/255.0 blue:182/255.0 alpha:1.0f];
    [self.view addSubview:countdownLable];
    _mainTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64+100*kScale, kScreenW, kScreenH-64-100*kScale) style:UITableViewStyleGrouped];
    _mainTableView.delegate = self;
    _mainTableView.dataSource = self;
    [self.view addSubview:_mainTableView];
    [self request];
    
    
    
    
    
}
- (void)request
{
    NSString *urlStr = [NSString stringWithFormat:@"%@/userCenter/userCenterIndex",APIYIGOU]
    ;
    
    DYBaseRequest *request = [DYBaseRequest new];
    request.requestUrl = urlStr;
    [request dyBgStartWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        NSDictionary *allDic = [NSDictionary changeType:request.responseJSONObject];
        [_mainTableView reloadData];
        NSLog(@"1111111%@",allDic);
    } error:^(YTKBaseRequest *request) {
        
    } failure:^(YTKBaseRequest *request) {
        [ViewFactory showErrorStrMsg:NETWORK_ERR];
    }];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 5;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * identifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell)
    {
        cell =[[NSBundle mainBundle ]loadNibNamed:@"ZYTableViewCell" owner:nil options:nil][0];
    }
//    if (indexPath.section==0)
//    {
//        <#statements#>
//    }
    if (indexPath.row==0) {
        UIImageView *buyerHeader = [[UIImageView alloc]init];
        [buyerHeader setImage:[UIImage imageNamed:@"set"]];
        buyerHeader.frame = CGRectMake(30*kScale, 30*kScale, 42*kScale, 42*kScale);
        [cell addSubview:buyerHeader];
        UILabel *buyerNameLable = [[UILabel alloc]init];
        buyerNameLable.frame = CGRectMake(90*kScale, 30*kScale, kScreenW, 42*kScale);
        buyerNameLable.text = @"王小花";
        buyerNameLable.font = [UIFont systemFontOfSize:15];
        [cell addSubview:buyerNameLable];
        UILabel *stateLable = [[UILabel alloc]init];
        stateLable.text = @"等待买家付款";
        stateLable.font = [UIFont systemFontOfSize:13];
        CGSize stateSize = [stateLable sizeThatFits:CGSizeMake(MAXFLOAT, 42*kScale)];
        stateLable.frame = CGRectMake(kScreenW-30*kScale-stateSize.width, 30*kScale, stateSize.width, 42*kScale);
        stateLable.textColor = [UIColor colorWithRed:14/255.0 green:161/255.0 blue:182/255.0 alpha:1.0f];
        [cell addSubview:stateLable];
    }
    else if (indexPath.row==1)
    {
        UIImageView *headerImage = [[UIImageView alloc]init];
        headerImage.frame = CGRectMake(30*kScale, 30*kScale, 150*kScale, 150*kScale);
        //        tribeHeaderImage.backgroundColor = [UIColor cyanColor];
        //    [tribeHeaderImage sd_setImageWithURL:[NSURL URLWithString:@"rest"]];
        [headerImage setImage:[UIImage imageNamed:@"rest"]];
        headerImage.layer.masksToBounds  = YES;
        headerImage.layer.cornerRadius = 8*kScale;
        [cell addSubview:headerImage];
        UILabel *introdocLable = [[UILabel alloc]init];
        introdocLable.font = [UIFont systemFontOfSize:13];
        introdocLable.numberOfLines = 3;
        //        introdocLable.lineBreakMode =  NSLineBreakByTruncatingTail;
        introdocLable.textColor = [UIColor colorWithRed:34/255.0 green:34/255.0 blue:34/255.0 alpha:1.0];
        NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init];
        style.lineSpacing = 5;
        introdocLable.text = @"我 额外还惊魂未定就会忘记很多毫无鳄鱼一起为  因为俄乌俄乌危机看见我去看健康";
        CGSize introSize = [introdocLable sizeThatFits:CGSizeMake(kScreenW-(150*kScale+3*30*kScale), MAXFLOAT)];
        
        //        NSDictionary *attributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:14], NSParagraphStyleAttributeName:style};
        //        introdocLable.attributedText = [[NSAttributedString alloc]initWithString:introdocLable.text attributes:attributes];
        
        
        introdocLable.frame = CGRectMake(150*kScale+2*30*kScale, headerImage.frame.origin.y, kScreenW-(150*kScale+3*30*kScale), introSize.height);
        
        [cell addSubview:introdocLable];
        UILabel *priceLable= [[UILabel alloc]init];
        priceLable.font = [UIFont systemFontOfSize:13];
        priceLable.text = @"Y280.00";
        CGSize numSize = CGSizeZero;
        
        numSize = [priceLable sizeThatFits:CGSizeMake(MAXFLOAT, 40*kScale)];
        priceLable.frame = CGRectMake(150*kScale+2*30*kScale, headerImage.frame.origin.y+150*kScale-40*kScale, numSize.width, 40*kScale);
        
        
        priceLable.textColor = [UIColor colorWithRed:189/255.0 green:40/255.0 blue:40/255.0 alpha:1.0];
        [cell addSubview:priceLable];
        UILabel *sellerClassLable= [[UILabel alloc]init];
        sellerClassLable.font = [UIFont systemFontOfSize:11];
        sellerClassLable.text = [NSString stringWithFormat:@"一口价"];
        sellerClassLable.textColor = [UIColor whiteColor];
        sellerClassLable.backgroundColor = [UIColor colorWithRed:14/255.0 green:161/255.0 blue:182/255.0 alpha:1.0f];
        CGSize seallerSize = [sellerClassLable sizeThatFits:CGSizeMake(MAXFLOAT, 40*kScale)];
        sellerClassLable.frame = CGRectMake(kScreenW-30*kScale-seallerSize.width, headerImage.frame.origin.y+150*kScale-40*kScale,seallerSize.width, 40*kScale);
        [cell addSubview:sellerClassLable];
    }
    if (indexPath.row==2)
    {
        UILabel *numLable= [[UILabel alloc]init];
        numLable.font = [UIFont systemFontOfSize:13];
        numLable.text = @"共一件商品";
        CGSize numSize = CGSizeZero;
        
        numSize = [numLable sizeThatFits:CGSizeMake(MAXFLOAT, 40*kScale)];
        numLable.frame = CGRectMake(210*kScale, 30*kScale, numSize.width, 40*kScale);
        //        numLable.textColor = [UIColor colorWithRed:189/255.0 green:40/255.0 blue:40/255.0 alpha:1.0];
        [cell addSubview:numLable];
        UILabel *allPriceLable= [[UILabel alloc]init];
        allPriceLable.font = [UIFont systemFontOfSize:13];
        allPriceLable.text = [NSString stringWithFormat:@"合计：¥200.00(含运费¥00.00)"];
        //        allPriceLable.textColor = [UIColor colorWithRed:136/255.0 green:136/255.0 blue:136/255.0 alpha:1.0];
        CGSize allPriceSize = [allPriceLable sizeThatFits:CGSizeMake(MAXFLOAT, 40*kScale)];
        allPriceLable.frame = CGRectMake(210*kScale+numSize.width+30*kScale, 30*kScale,allPriceSize.width, 42*kScale);
        [cell addSubview:allPriceLable];
        ZYButton *contactBtn = [[ZYButton alloc]initWithFrame:CGRectMake(kScreenW-30*kScale-178*kScale, 82*kScale, 178*kScale,60*kScale)];
        contactBtn.font = [UIFont systemFontOfSize:15];
        contactBtn.layer.cornerRadius  = 8*kScale;
        contactBtn.layer.masksToBounds = YES;
        contactBtn.layer.borderWidth = 1.0f;
        contactBtn.layer.borderColor = [UIColor lightGrayColor].CGColor;
        [contactBtn setTitle:@"联系买家" forState:UIControlStateNormal];
        [contactBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [cell addSubview:contactBtn];
        ZYButton *stateBtn = [[ZYButton alloc]initWithFrame:CGRectMake(kScreenW-30*kScale-178*2*kScale-30*kScale, 82*kScale, 178*kScale,60*kScale)];
        stateBtn.font = [UIFont systemFontOfSize:15];
        stateBtn.layer.cornerRadius  = 8*kScale;
        stateBtn.layer.masksToBounds = YES;
        stateBtn.layer.borderWidth = 1.0f;
        stateBtn.layer.borderColor = [UIColor lightGrayColor].CGColor;
        [stateBtn setTitle:@"查看物流" forState:UIControlStateNormal];
        [stateBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [cell addSubview:stateBtn];
    }
    
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row==0) {
        return 100*kScale;
    }
    else if (indexPath.row==1)
    {
        return 210*kScale;
    }
    return 164*kScale;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section==0)
    {
        return 30*kScale;
    }
    return 20*kScale;
}
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
